package com.itheima.arrlist;
import java.util.ArrayList;
public class ArrayListDemo06 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student student1 = new Student("张三",19);
        Student student2 = new Student("张四",17);
        Student student3 = new Student("张五",16);
        Student student4 = new Student("张六",15);
        Student student5 = new Student("张七",20);
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student5);
        ArrayList<Student> studentAge = getStudentAge(list);

        for (int i = 0; i < studentAge.size(); i++) {
            Student s = studentAge.get(i);
            System.out.println(s.getName()+","+s.getAge());

        }

    }

    public static ArrayList<Student> getStudentAge(ArrayList<Student> list) {
        ArrayList<Student> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if (student.getAge() < 18) {
                newList.add(student);
            }

        }
     return newList;
    }
}
